﻿namespace NiYo.ParserBuilder.Domain.Hl7.DataTypes
{
    /// <summary>
    /// CE
    /// </summary>
    public class CodedElement : Hl7DataType
    {
        /// <summary>
        /// Unique Identifier.
        /// Standard HL7 position: 1
        /// </summary>
        public string Identifier { get; set; }

        /// <summary>
        /// Name or description of the item in question.
        /// Standard HL7 position: 2
        /// </summary>
        public string Text { get; set; }

        /// <summary>
        /// The name of the coding system.
        /// Standard HL7 position: 3
        /// </summary>
        public string NameOfCodingSystem { get; set; }

        /// <summary>
        /// Alternate Identifier.
        /// Standard HL7 position: 4
        /// </summary>
        public string AlternateIdentifier { get; set; }

        /// <summary>
        /// Alternate Text.
        /// Standard HL7 position: 5
        /// </summary>
        public string AlternateText { get; set; }

        /// <summary>
        /// Name Of Alternate Coding System.
        /// Standard HL7 position: 6
        /// </summary>
        public string NameOfAlternateCodingSystem { get; set; }

        #region "- Helper Methods -"

        /// <summary>
        /// To compare current CodedElement with another CodedElement
        /// </summary>
        /// <returns></returns>
        private bool Equals(CodedElement other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;
            return Equals(other.Identifier, Identifier) && Equals(other.Text, Text) && Equals(other.NameOfCodingSystem, NameOfCodingSystem) && Equals(other.AlternateIdentifier, AlternateIdentifier) && Equals(other.AlternateText, AlternateText) && Equals(other.NameOfAlternateCodingSystem, NameOfAlternateCodingSystem);
        }

        /// <summary>
        /// To compare current CodedElement with another object
        /// </summary>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            if (obj.GetType() != typeof(CodedElement)) return false;
            return Equals((CodedElement)obj);
        }

        /// <summary>
        /// Used by Equals method to compare objects
        /// </summary>
        /// <returns></returns>
        public override int GetHashCode()
        {
            unchecked
            {
                var result = (Identifier != null ? Identifier.GetHashCode() : 0);
                result = (result * 397) ^ (Text != null ? Text.GetHashCode() : 0);
                result = (result * 397) ^ (NameOfCodingSystem != null ? NameOfCodingSystem.GetHashCode() : 0);
                result = (result * 397) ^ (AlternateIdentifier != null ? AlternateIdentifier.GetHashCode() : 0);
                result = (result * 397) ^ (AlternateText != null ? AlternateText.GetHashCode() : 0);
                result = (result * 397) ^ (NameOfAlternateCodingSystem != null ? NameOfAlternateCodingSystem.GetHashCode() : 0);
                return result;
            }
        }

        #endregion
    }
}
